<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_News_Hooks_Formatcontent_Hook extends Gio_Core_Hook
{
	/**
	 * @param array $links
	 * @param string $lang
	 * @return array
	 */
	public static function filter($content, $webId = null)
	{
		switch ($webId) {
			case 'vnexpress':	
				$content = str_replace('file","/', 'file","http://vnexpress.net/', $content);
				$content = str_replace('SWFObject("', 'SWFObject("http://vnexpress.net', $content);
				//$content = str_replace('playlistfile=/', 'playlistfile=http://vnexpress.net/', $content);
				$content = str_replace("swfobject.embedSWF('", "swfobject.embedSWF('http://vnexpress.net", $content);
				$content = str_replace('/Service/FlashVideo/Playlist2.asp?Id=', 'http://vnexpress.net/Service/FlashVideo/Playlist2.asp?Id=', $content);
				$content = str_replace('"skin","/Library/Common/AdsPlayer/classic/classic.xml"', '"skin","http://vnexpress.net/Library/Common/AdsPlayer/classic/classic.xml"', $content);
				$content = str_replace('skin=/Library/Common/AdsPlayer/classic/classic.xml', 'skin=http://vnexpress.net/Library/Common/AdsPlayer/classic/classic.xml', $content);
				$content = str_replace('http://vnexpress.nethttp', 'http', $content);
				break;
			case 'ngoisao':	
				$content = str_replace('file","/', 'file","http://ngoisao.net', $content);
				$content = str_replace('SWFObject("', 'SWFObject("http://ngoisao.net', $content);
				$content = str_replace("swfobject.embedSWF('", "swfobject.embedSWF('http://ngoisao.net", $content);
				$content = str_replace('/Service/FlashVideo/Playlist2.asp?Id=', 'http://ngoisao.net/Service/FlashVideo/Playlist2.asp?Id=', $content);
				break;
			case 'thethaovanhoa':
				$content = str_replace('/images/mediaplayer.swf', 'http://thethaovanhoa.vn/images/mediaplayer.swf', $content);
				$content = str_replace('/scripts/swfobject', 'http://thethaovanhoa.vn/scripts/swfobject', $content);
				break;
			case 'haisao':
			case 'bongda':
			case 'nguoilaodong':	
				require_once LIB_DIR . DS . 'htmlpurifier' . DS . 'HTMLPurifier.auto.php';
				$purifier = new HTMLPurifier();
				$content = $purifier->purify($content);
				break;
			case 'haitugio':
				$configs = Gio_Core_Config_Xml::getConfig('web');
				$content = str_replace('//<![CDATA[', '', $content);
				$content = str_replace('//]]>', '', $content);
				$content = str_replace('flashWrite("/', 'flashWrite("' . $configs->url . '/flash.php?url=http://24h.com.vn/', $content);
				//$content = str_replace('500', '480', $content);
				//$content = str_replace('477', '400', $content);
				break;
			case 'zing':
				$content = '<script type="text/javascript">o_ChannelRoot = null;</script>' . $content;
				break;
		}
		
		if ($webId) {
			$content = Gio_Core_String::stripTags($content, array('a'));
		}
		return $content;
	}
}
